//
//  LFloginViewController.m
//  LocalLife
//
//  Created by 李立达 on 15/11/22.
//  Copyright (c) 2015年 heima11. All rights reserved.
//

#import "LFloginViewController.h"

@interface LFloginViewController ()
@property (weak, nonatomic) IBOutlet UITextField *userLaber;
@property (weak, nonatomic) IBOutlet UITextField *password;

@property (weak, nonatomic) IBOutlet UIButton *remberButton;
- (IBAction)loginButton:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *loginButton;

@end

@implementation LFloginViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.titleLabel.text = @"login";
    self.rightButton.hidden = YES;
    self.tabBarController.tabBar.hidden=YES;
    [self.remberButton setImage:[UIImage imageNamed:@"btn_selected"] forState:UIControlStateSelected];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textChange) name:UITextFieldTextDidChangeNotification object:self.userLaber];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textChange) name:UITextFieldTextDidChangeNotification object:self.password];
}
-(void)textChange
{
    if(self.userLaber.text.length>0&&self.password.text.length>0)
    {
        self.loginButton.enabled=YES;
    }
    else
    {
        self.loginButton.enabled=NO;
    }
}
- (void)backMethod
{
    [self.navigationController popViewControllerAnimated:YES];

    AppDelegate* app = [UIApplication sharedApplication].delegate;
    [app.tabar showHiddenbottmView:NO];
}

- (IBAction)remberPasswd:(id)sender {
    self.remberButton.selected=!self.remberButton.selected;
}

- (IBAction)loginButton:(id)sender {
    UIButton *button=sender;
   
        button.enabled=YES;
        NSString *userstr=self.userLaber.text;
        NSString *pattern=@"^[a-z0-9A-Z]+@[a-z0-9A-Z]+.[a-z0-9A-Z]{2,6}$";
        NSString *pattern2=@"1[0-9]{10}";
        NSRegularExpression *regular = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:nil];
        NSArray *allResult =   [regular matchesInString:userstr options:NSMatchingReportCompletion range:NSMakeRange(0, userstr.length)];
        NSRegularExpression *regular1 = [NSRegularExpression regularExpressionWithPattern:pattern2 options:0 error:nil];
        NSArray *allResult1 =   [regular1 matchesInString:userstr options:NSMatchingReportCompletion range:NSMakeRange(0, userstr.length)];
        if(allResult.count==1||allResult1.count==1)
        {
            NSLog(@"登录成功");
        }
        else
        {
            NSLog(@"登录失败");
        }
   
    
}
- (IBAction)sinaLogin:(id)sender {
}

@end
